<template>
<div class="communication-sms-edit">
	<Row>
		<Col :span="24">
			<Breadcrumb>
				<BreadcrumbItem to="/" @click.native="changeMenu(0)"><Icon type="home"></Icon> 首页</BreadcrumbItem>
				<BreadcrumbItem :to="{'name':'communication-sms-index'}">短信管理</BreadcrumbItem>
				<BreadcrumbItem>{{title}}</BreadcrumbItem>
			</Breadcrumb>
			<div class="cleaner20"></div>
		</Col>
	</Row>
	<Form ref="vform" :model="vform" :label-width="100"  :rules="ruleValidate">
		<Row type="flex" :gutter="16">
			
		</Row>
	</Form>


</div>
</template>
<script>
// 引入子组件
import hljs from 'highlight.js'
import 'highlight.js/styles/vs2015.css'

// quill编辑器的字体
var fonts = ['SimSun', 'Microsoft-YaHei','Arial','Times-New-Roman','sans-serif'];  
var Font = Quill.import('formats/font'); 
Font.whitelist = fonts; //将字体加入到白名单 
Quill.register(Font, true);
// 引入子组件
import {mapState,mapGetters} from 'vuex'
import { Tag, Card, Page, Modal, Spin, Row, Col, ButtonGroup, Button,  Breadcrumb, BreadcrumbItem, Icon, Form, FormItem, Input, Select, Option, DatePicker, InputNumber } from 'iview';
export default { 
	name:'welisten-talk-edit',
	components: { Tag, Card, Page, Modal, Spin, Row, Col, ButtonGroup, Button, Breadcrumb, BreadcrumbItem, Icon, Form, FormItem, Input, Select, Option, DatePicker, InputNumber},
	data () {
		return {
			title:'编辑',
			showBox:false,
			listenerObj:{},
			created_at:'',
			ruleValidate: {
				nickname: [
					{ required: true, message: '请选择倾听者', trigger: 'blur' },
				],
				status: [
					{ required: true, message: '请填写状态', trigger: 'change', type:'number' }
				],
				sequence: [
					{ required: true, message: '请填写权重', trigger: 'change', type:'number' }
				],
			},			
			editorOption:{
				placeholder:'请输入内容',
				modules:{
					imageResize: {},
					toolbar:{
                        container: [
							['bold', 'italic', 'underline'],        // toggled buttons
							[{ 'size': ['small', false, 'large', 'huge'] }],  // custom dropdown
							[{ 'header': [1, 2, 3, 4, 5, 6, false] }],

							[{ 'color': [] }, { 'background': [] }],          // dropdown with defaults from theme
							[{ 'font': fonts }],
							['clean'], 
                        ],
                    },
					syntax: {highlight:text => hljs.highlightAuto(text).value},


				}
			},
			vform:{
				status: 0,
				nickname: null,
				sequence:1,
				memo:'',
				uid:'',
				content:''
			},
			statusNames:['暂存','正常','关闭'],
			statusList: [
				{value: 0,label: '暂存'},
				{value: 1,label: '正常'},
				{value: 2,label: '关闭'},
			],
		}
	},
	methods:{
		init:function(){
			
			let self=this
			self.$store.dispatch("setSpinShow",true)
			function action2(){return self.$http.get("/v1/welisten/talks/"+self.$route.params.id,{params: { 'token': self.token }})}
			
			self.$http.all([action2()])
			.then(self.$http.spread(function (response2){
				if(200==response2.data.status && 0==response2.data.code){
					response2.data.data.best_reply_id=parseInt(response2.data.data.best_reply_id)
					response2.data.data.reply_qty=parseInt(response2.data.data.reply_qty)
					response2.data.data.sequence=parseInt(response2.data.data.sequence)
					response2.data.data.status=parseInt(response2.data.data.status)
					self.created_at=self.dateFormat(new Date(response2.data.data.created_at*1000),'yyyy-MM-dd')
					self.vform=response2.data.data
				}else{self.$Message.error(response2.data.message)}
				
				self.$store.dispatch("setSpinShow",false)
			})).catch(self.$http.spread(function (error2) {
				self.$store.dispatch("setSpinShow",false)
			}))
		},
		onRowDelete(id,statusId){
			this.$Modal.confirm({
				title: '温馨提示',
				content: '删除后不可恢复，确认删除？',
				onOk: () => {
					this.changeStatus(id,statusId)
				},
			})
		},
		changeStatus:function(uid,statusId){
			let self=this
			
			self.$http.post("/v1/welisten/talks?_method=put&token="+self.token,{'id':uid,'data':'{"status":"'+parseInt(statusId)+'"}'})
			.then(function(response){
				
				if(200==response.data.status && 0==response.data.code)
				{
					if(3==statusId){self.$router.push({path:'/welisten/talk/index'})}
					self.vform.status=statusId
					self.$Message.success('操作成功');
				}else{
					self.$Message.error(response.data.message)
				}
			}).catch(function(error){
				self.$Message.error( error.message)
				
			})
		},
		onSave:function(index){
			let self=this
			let _flag=true
			this.$refs.vform.validate((valid) => {
				if (!valid){
					this.$Message.error('请完成必填项')
					_flag=false
				}
			})
			if(!_flag){return}
			self.$store.dispatch("setSpinShow",true)
			self.$http.post("/v1/welisten/talks?_method=put&token="+self.token,{'id':self.$route.params.id,'data':JSON.stringify(this.vform)})
			.then(function(response){
				if(200==response.data.status && 0==response.data.code)
				{
					self.$Message.success('操作成功')
				}else{
					self.$Message.error(response.data.message)
				}
				self.$store.dispatch("setSpinShow",false)
			}).catch(function(error){
				self.$Message.error(error.message)
				self.$store.dispatch("setSpinShow",false)
			})
		},
	},
	created:function(){
	},
	mounted () {
    	this.setTitle(this.title)
	},
	activated:function(){
		this.init()
	},
	computed:{
		...mapGetters(['token','menuIndex'])
	},
}



</script>

<style lang="less" scoped>
</style>